Skip to content

fix(proxy): populate contribution USD savings#1751

Open
ketpatil77 wants to merge 3 commits into
headroomlabs-ai:mainfrom
ketpatil77:codex/headroom-windows-loop-config
Open

fix(proxy): populate contribution USD savings#1751
ketpatil77 wants to merge 3 commits into
headroomlabs-ai:mainfrom
ketpatil77:codex/headroom-windows-loop-config

Conversation

@ketpatil77

@ketpatil77 ketpatil77 commented Jul 3, 2026

Copy link
Copy Markdown

Description

Populate session contribution USD totals for compression and cache reads.

AnthropicHandlerMixin now records both compression savings and cache-read savings in dollars instead of leaving those fields at 0.

Closes #1751

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Changes Made

  • headroom/proxy/savings_tracker.py: added _estimate_cache_savings_usd() alongside existing compression-savings helper.
  • headroom/proxy/handlers/anthropic.py: passes computed compression and cache savings USD into update_contribution().
  • tests/test_proxy_cache_savings_usd.py: added regression tests for new cache-savings helper.

Testing

  • Unit tests pass (pytest)
  • Linting passes (ruff check .)
  • Type checking passes (mypy headroom)
  • New tests added for new functionality
  • Manual testing performed

Test Output

$ pytest tests/test_proxy_cache_savings_usd.py
Focused cache-savings regression suite passed during local verification before PR submission.

$ ruff check headroom/proxy/savings_tracker.py headroom/proxy/handlers/anthropic.py tests/test_proxy_cache_savings_usd.py
Lint checks passed during local verification before PR submission.

Real Behavior Proof

  • Environment: Local Headroom proxy savings-tracker path for Anthropic contribution updates.
  • Exact command / steps: Verified helper and handler wiring that computes compression and cache-read USD totals before calling update_contribution().
  • Observed result: Contribution savings fields populate with nonzero dollar estimates when model pricing is available.
  • Not tested: Full live Anthropic upstream session in this verification pass.

Review Readiness

  • I have performed a self-review
  • This PR is ready for human review

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the CHANGELOG.md if applicable

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

PR governance

This PR follows the template and is marked ready for human review.

@github-actions github-actions Bot added the status: needs author action Pull request body or readiness checklist still needs author updates label Jul 3, 2026

@JerrettDavis JerrettDavis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the contribution USD wiring. The new cache-read estimate follows the existing LiteLLM model resolution pattern, treats missing pricing and non-discounted cache reads as zero, and the Anthropic contribution update now passes both compression and cache savings dollars alongside the existing token counts. Focused tests cover the cache pricing helper; checks are green. This looks ready.

@github-actions github-actions Bot added status: ready for review Pull request body is complete and the author marked it ready for human review and removed status: needs author action Pull request body or readiness checklist still needs author updates labels Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Pull request body is complete and the author marked it ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants